//
//  WeiboTableViewCell.swift
//  weiboSwift1.0
//
//  Created by xuNick on 16/4/20.
//  Copyright © 2016年 NN. All rights reserved.
//

import UIKit

let CellMagin:CGFloat = 5

// 头像的大小
let StatusCellHeadImgWH: CGFloat = 35

//content宽度
let KcontentW:CGFloat = UIScreen.mainScreen().bounds.width - 2 * CellMagin

let KsubviewColor = UIColor.whiteColor()


class WeiboTableViewCell: UITableViewCell {
    
    
    var weiboCellModel:WeiboCellViewModel? {
        didSet{
            // TODO: 给originalview赋值
            originalView.userInfo = weiboCellModel
            
            //
            retweetView.viewModel = weiboCellModel
            
            //赋值自己图片
            picme.pics = weiboCellModel?.pic_me
            
        
            picRetweet.pics = weiboCellModel?.pic_retweet
            
            picme.snp_updateConstraints { (make) -> Void in
                make.height.equalTo(picme.h)
            }
            
            picRetweet.snp_updateConstraints { (make) -> Void in
                make.height.equalTo(picRetweet.h)

            }
//            self.layoutIfNeeded()
        
        }
    }
    
    
//    override func layoutSubviews() {
//        super.layoutSubviews()
//        picme.snp_updateConstraints { (make) -> Void in
//            make.height.equalTo(picme.h)
//        }
//        
//        picRetweet.snp_updateConstraints { (make) -> Void in
//            make.height.equalTo(picRetweet.h)
//            
//        }
//        
//        contentView.snp_updateConstraints { (make) -> Void in
//            make.bottom.equalTo(statusTool.snp_bottom).offset(0.1)
//            make.leading.top.trailing.equalTo(self)
//        }
//
//
//    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: CellID)
        self.backgroundColor = KbackGroundColor
        self.setupUI()
        
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        
        self.contentView.addSubview(originalView)
        self.contentView.addSubview(retweetView)
        self.contentView.addSubview(statusTool)
        self.contentView.addSubview(picme)
        self.contentView.addSubview(picRetweet)
        //TODO:  再连个地方都添加了约束什么意思
        originalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.contentView).offset(CellMagin)
            make.leading.trailing.equalTo(self.contentView)
//            make.bottom.equalTo((originalView.icon?.snp_bottom)!).offset(CellMagin)
        }
        retweetView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(picme.snp_bottom)
            make.leading.equalTo(self)
            make.trailing.equalTo(self)
        }
        
        statusTool.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(picRetweet.snp_bottom)
            make.leading.trailing.equalTo(self)
            make.height.equalTo(30)
        }
        //picme 约束
       
        picme.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.leading.trailing.equalTo(contentView)
            make.height.equalTo(picme.h)
        }
        //picRetweet 约束
        picRetweet.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetView.snp_bottom)
            make.leading.trailing.equalTo(contentView)
            make.height.equalTo(picRetweet.h)

        }
        
        
        contentView.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(statusTool.snp_bottom)
            make.leading.top.trailing.equalTo(self)
        }
        
    }
    
    
    //MARK: - 懒加载控件
    
    lazy var originalView:OriginalView = OriginalView()
    
    lazy var statusTool:StatusTools = StatusTools()

    lazy var retweetView:RetWeetView = RetWeetView()
    
    lazy var picme:PicturesView = {
       let view = PicturesView(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout())
        return view
    }()
    lazy var picRetweet:PicturesView = {
        let view = PicturesView(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout())
        
        return view

    }()
}
